import 'package:boss/ui/page/booking/bookingHistory/provider/booking_history_provider.dart';
import 'package:boss/ui/page/booking/bookingHistory/widget/booking_history_item.dart';
import 'package:boss/ui/widget/button/radius_button.dart';
import 'package:boss/ui/widget/calendar_bar.dart';
import 'package:boss/ui/widget/loader/loader_pull_refresh.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'booking_history_header.dart';

class BookingHistoryBrowser extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Consumer<BookingHistoryProvider>(
          builder: (context, provider, _) => Container(
            margin: EdgeInsets.symmetric(vertical: 30.w),
            padding: EdgeInsets.symmetric(horizontal: 25.w),
            child: Row(
              children: <Widget>[
                Expanded(
                  child: CalendarBar(
                    startDateTime: provider.startTime,
                    endDateTime: provider.endTime,
                    onDateTimeChanged: provider.setStartTime,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 20.w),
                  child: RadiusButton(
                    width: 160.w,
                    height: 60.w,
                    title: '查询',
                    onTap: () {
                      provider.refreshKey.currentState.refresh();
                    },
                  ),
                ),
              ],
            ),
          ),
        ),
        Expanded(
          child: Consumer<BookingHistoryProvider>(
            builder: (context, provider, _) => LoaderPullRefresh(
              key: provider.refreshKey,
              loadTask: provider.loadMore,
              refreshTask: provider.refresh,
              builder: (context) => ListView.builder(
                padding: EdgeInsets.symmetric(
                  horizontal: 25.w,
                ),
                itemBuilder: (context, index) {
                  if (index == 0) {
                    return BookingHistoryHeader();
                  }

                  return BookingHistoryItem(provider.bookInfoList[index - 1]);
                },
                itemCount: provider.bookInfoList.length + 1,
              ),
            ),
          ),
        ),
      ],
    );
  }
}
